/*
 *  lib-smv: Matrix - Vector Library targeted to Structural Mechanics Problems
 *  Copyright (C) 2006-2008  St.Brcic, Lj.Zugic
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
/** @file Lanczos.h
 *  @brief Definition of class Lanczos - solution of the eigenvalue problem
 *
 *  EIGENVALUE PROBLEMS:  Class LANCZOS  
 *  STANDARD AND GENERALIZED EIGENVALUE PROBLEMS 
 *  A*x = L*x and A*x = L*B*x
 * 
 *  Lanczos transformation 
 */ 

#ifndef _LANCZOS_H
#define _LANCZOS_H

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <string>
#include "Arrays.h"
#include "iArrays.h"

using namespace std;

namespace smv_lib
{
/**
* \brief class Lanczos
*
*  EIGENVALUE ANALYSIS, STANDARD AND GENERALIZED PROBLEMS
*  ( A*x = L*x and A*x = L*B*x )
*
*  Lanczos algorithm applied to standard and
*  generalizeg eigenvalue problems of Hermitian matrices
**  symmetric and positive definite (SPD).
*  Vector and Matrix classes (of doubles and ints) are used
*  (mainly according to "Numerical Recipes in C").
*/
class Lanczos
{
private:
	//! Matrix A for the standard eigenvalue problem A*x = Lambda*x
	Matrix A;
	//! Matrix B for the generalized eigenvalue problem A*x = Lambda*B*x
	Matrix B;
	//! Order of matrices A and B
	int N;
	//! Number of eigenvalue/eigenvector pairs
	int No_Lanc;
	//! Modal matrix: columns of V are eigenvectors
	Matrix V;
	//! Vector of eigenvalues: Spectral vector (matrix)
	Vector d;

	//--- control data
	//! Indicator: true if matrix A is given - for standard problem
	bool isMatrix_A;     
	//! Indicator: true if matrix B is given - for generalized problem
	bool isMatrix_B;   
	//! Indicator: true if the problem is solved
	bool isCalculated;

public:
	//! empty (default) constructor
	Lanczos(void);
	//! constructor for the standard complete or partial problem (n <= N)
	Lanczos(Matrix& a, int n);
	//! constructor for the generalized complete or partial problem (n <= N)
	Lanczos(Matrix& a, Matrix& b, int n);
	//! destructor
	~Lanczos(void);

	//--------- set and get functions (in case of a default constructor)
	//! set Matrix A (for standard problem)
	void setMatrix_A(Matrix& a);     
	//! set Matrices A and B (for generalized problem)
	void setMatrix_B(Matrix& a, Matrix& b);  
	//! set number of eigenvalue/vector pairs
	void setNumber(int n);

	//--------- calculate eigenvectors and eigenvalues
	void calculate();
	//--------- give the results 
	//! give the modal matrix
	Matrix& giveModalMatrix();
	//! give the vector with eigenvalues
	Vector& giveSpectrum();

private:
	//! standard Lanczos transformation
	void stLanczos();
	void standLanczos(int m);
	//! generalized Lanczos transformation
	//! sort obtained eigenvecetors / eigenvalues
 	void eigsrt_Lanc();
	//! generalized Jacobi transformation
	void genLanczos();  
};

}  // end of namespace smv_lib

#endif //  _LANCZOS_H

//=============================== end of file
